home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / Lyapunov / ColorMapView.m < prev    next >
Encoding:
Text File  |  1992-07-31  |  2.2 KB  |  104 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "ColorMapView.h"
  5. #import "ColorMap.h"
  6. #import <stdio.h>
  7. #import <stdlib.h>
  8. #import <strings.h>
  9. #import <defaults.h>
  10. #import <appkit/tiff.h>
  11. #import <appkit/color.h>
  12. #import <appkit/graphics.h>
  13. #import <appkit/Control.h>
  14. #import <appkit/OpenPanel.h>
  15. #import <appkit/Application.h>
  16. #import <dpsclient/psops.h>
  17. #import <dpsclient/wraps.h>
  18.  
  19. #define COLCONV (NUMCOLORS - 1.0)
  20.  
  21. @implementation ColorMapView
  22.  
  23. - initFrame:(const NXRect *)frm        // designated initializer
  24. {
  25.     char *slashPos;
  26.  
  27.     [super initFrame:frm];
  28.     first = YES;
  29.     colorMap = [[ColorMap alloc] init];
  30.     
  31. // get .app wrapper pathname
  32.  
  33.     appPath = (char *)malloc(256);
  34.     strcpy(appPath, NXArgv[0]);
  35.     if (slashPos = strrchr(appPath, '/')) {
  36.         sprintf(slashPos+1, "\0");
  37.     } else {
  38.         strcpy(appPath, "./");
  39.     }
  40.     return self;
  41. }
  42.  
  43. - colorMap
  44. {
  45.     return colorMap;
  46. }
  47.  
  48. - loadMap:sender
  49. {
  50.     const char *const *files;
  51.     char *file, *mapPath;
  52.     const char *dir;
  53.     static const char *const ft[2] = {"map", NULL};
  54.     
  55.     id openPanel = [OpenPanel new];
  56.     [openPanel allowMultipleFiles:NO];
  57.     if (first) {
  58.         mapPath = (char *)malloc(1024);
  59.         strcpy(mapPath, appPath);
  60.         strcat(mapPath,"maps");
  61.         [openPanel runModalForDirectory:mapPath file:NULL types:ft];
  62.         first = NO;
  63.         free(mapPath);
  64.     }
  65.     else  [openPanel runModalForTypes:ft];
  66.     files = [openPanel filenames];
  67.     dir = [openPanel directory];
  68.     if (!files) return self;
  69.     if (!files[0]) return self;
  70.     file = malloc(strlen(files[0]) + strlen(dir) + 8);
  71.     strcpy(file, dir);
  72.     strcat(file,"/");
  73.     strcat(file, files[0]);
  74.     strcat(file, "\0");
  75.     [colorMap initFromFile:file];
  76.     [self update];
  77.     return self;
  78. }
  79.  
  80. - drawSelf:(NXRect *)rects :(int)rectCount    // internal method
  81. {    // this is super simple, but doing a wrap would still help.
  82.     register int i;
  83.     int r, g, b;
  84.     
  85.     NXDrawGrayBezel(&bounds, rects);
  86.     for (i=0; i<NUMCOLORS; i++) {
  87.         [colorMap colorFor:i :&r :&g :&b];
  88.         NXSetColor(NXConvertRGBToColor(r/COLCONV, g/COLCONV, b/COLCONV));
  89.         PSmoveto(i + NX_X(&bounds) + OFFSET, NX_Y(&bounds) + OFFSET);
  90.         PSlineto(i + NX_X(&bounds) + OFFSET,
  91.             NX_Y(&bounds) + NX_HEIGHT(&bounds) - OFFSET);
  92.         PSstroke();
  93.     }
  94.     return self;
  95. }
  96.  
  97. - free
  98. {
  99.     [colorMap free];
  100.     return self;
  101. }
  102.  
  103. @end
  104.